package cn.com.netedge.iot.frontend.comm.mq;

import cn.com.netedge.iot.frontend.comm.constants.AppConstant;
import cn.com.netedge.iot.frontend.comm.vo.DelayMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Scope("prototype")
public class DelaySendMessageTask {
    private static final Logger logger = LoggerFactory.getLogger(DelaySendMessageTask.class);

    @Async("asyncServiceExecutor")
    public void sendMessage(String deviceNumber, int deviceType, String message) {
        String key = deviceNumber + "_" + deviceType;
        List<DelayMessage> messageList = AppConstant.rtuDelayMessageMap.get(key);
        if(messageList == null) {
            messageList = new ArrayList<>(10);
            AppConstant.rtuDelayMessageMap.put(key, messageList);
        }
        DelayMessage delayMessage = new DelayMessage();
        delayMessage.setMessage(message);
        delayMessage.setCreateTime(System.currentTimeMillis());
        messageList.add(delayMessage);
    }
}